<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../lib/vue.js"></script>
    <script src="../lib/vue-router.js"></script>
</head>
<body>
    <div id="app">
        <!-- 如果在link中传递参数 不影响路由规则-->
        <router-link to="/login?id=10">登录</router-link>
        <!-- 以/param的形式传递参数 -->
        <router-link to="/register/12">注册</router-link>

        <router-view></router-view>
    </div>

    <script>
        var login = {
            template:'<h1>登录组件</h1>',
            created () {
                // 获取link入口传递的参数 通过query获取
                console.log(this.$route.query.id);
            }
        }
        var register = {
            template:'<h1>注册组件</h1>',
            created () {
                // 以param形式传递参数 需要通过params属性获取
                console.log(this.$route.params)
            }
        }
        var myRoute = [
            { path: '/login', component: login },
            { path: '/register/:id', component: register }
        ]
        // 路由实例里是通过routes属性引入的
        var routeObject = new VueRouter({
            routes:myRoute
        })
        var vm = new Vue({
            el:'#app',
            data:{},
            methods: {
                
            },
            router: routeObject
        })
    </script>
</body>
</html>